package com.multimedia.scala

object FunctionXY {

	def sqadd2(x: Int) (y: Int): Int = {
	    println("start")
	    return x*x + y*y
	}
	
	def process[A](list:List[A])(filter:A=>Boolean):List[A] = {
		lazy val recurse = process (_:List[A]) (filter)
		println(list)
		list match {
		case head::tail => if (filter(head)) {
		    head::recurse(tail)
		  } else {
		    recurse(tail)
		  }
		  case Nil => Nil
		}
	}
 
	val even = (a:Int) => a % 2 == 0
 
	val numbersAsc = 1::2::3::4::5::Nil
	val numbersDesc = 5::4::3::2::1::Nil
 
	def main(args: Array[String]) {
		println(process(numbersAsc)(even))   // [2, 4]
		//println(process(even)(numbersDesc))  // [4, 2]
		val processEvens = process(_:List[Int])(even)
		println(processEvens(numbersDesc))
	}
}